﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Diagnostics;

namespace ResUma
{
    public partial class OcupatiiFrm : FrmTreeRezumat
    {
        public OcupatiiFrm(ModuleClass mInfo)
            : base(mInfo)
        {
            numeMacheta = Text;
            InitializeComponent();
            workConnString = "ESRPConnectionString";
            ColoanaParinte = "IDOcupatieParinte";
            txtRoot = "Ocupatii";
            localTree = OcupatiiTV;
            eSRPDataSet.Ocupatii.IDOcupatieParinteColumn.DefaultValue = 0;
            HandleFillTree += new TreeLoadHandler(Frm_HandleFillTree);
        }

        private void OcupatiiFrm_Load(object sender, EventArgs e)
        {
            //Trace.Assert(CodUnitate != -1, "Va rugam sa setati codul unitatii!");
            this.ocupatiiTableAdapter.Connection = DeschideConexiune(workConnString);
            //this.tipDepartamentTableAdapter.FillByActiv(eSRPDataSet.TipDepartament);
            //this.departamenteTableAdapter.Connection = this.tipDepartamentTableAdapter.Connection;
            //this.ocupatiiTableAdapter.Fill(eSRPDataSet.Ocupatii);
            this.listBndSourceMain.Add(ocupatiiBindingSource);
            this.listTableAdaptor.Add(ocupatiiTableAdapter.Adapter);

            this.OcupatiiTV.Nodes.Clear();
            TreeNode tnRoot = this.OcupatiiTV.Nodes.Add(txtRoot);
            Int32 id = 0;
            tnRoot.Tag = new NodeInfo(id);
            ColoanaPK = "IDOcupatie";
            ColoanaNume = "Denumire";
            LoadTree(tnRoot, ocupatiiTableAdapter.Connection, String.Empty);
            OcupatiiTV.SelectedNode = tnRoot;

            AddButton("Salvare", global::ERPStudio.Properties.Resources.salvare1, Salvare, ToolStripItemAlignment.Right, true);
            InchideConexiune(ocupatiiTableAdapter.Connection);
            Text = numeMacheta + " - " + ((OcupatiiTV.SelectedNode != null) ? OcupatiiTV.SelectedNode.Text : "");

        }

        void Frm_HandleFillTree(object sender, TreeViewEventArgs e)
        {
            //Trace.Assert(CodUnitate != -1, "Va rugam sa setati codul unitatii!");
            this.ocupatiiTableAdapter.Connection = DeschideConexiune(workConnString);
            NodeInfo nodI = e.Node.Tag as NodeInfo;
            this.ocupatiiTableAdapter.GetChild(eSRPDataSet.Ocupatii, Convert.ToInt32(nodI.ID));
            InchideConexiune(this.ocupatiiTableAdapter.Connection);
        }
    }
}
